package com.example.interviewrecorder

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.interviewrecorder.dao.LyyUserDao
import com.example.interviewrecorder.dao.RecordDao
import com.example.interviewrecorder.dao.SecurityQuestionDao
import com.example.interviewrecorder.model.LyyUser
import com.example.interviewrecorder.model.Record
import com.example.interviewrecorder.model.SecurityQuestion

@Database(
    version = 1,
    entities = [LyyUser::class, Record::class, SecurityQuestion::class],
    exportSchema = false
)
abstract class LyyDatabase : RoomDatabase() {
    abstract fun getLyyUserDao(): LyyUserDao
    abstract fun getRecordDao(): RecordDao
    abstract fun getSecurityQuestionDao(): SecurityQuestionDao

    companion object {
        private const val DATABASE_NAME = "lyy_database"
        private var instance: LyyDatabase? = null

        @Synchronized
        fun getDatabase(): LyyDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(
                LyyApplicaiton.context,
                LyyDatabase::class.java,
                DATABASE_NAME
            ).build().apply {
                instance = this
            }
        }
    }
}